import path from 'path'
import url from 'url'

import { machineIdSync } from 'node-machine-id'

export const APP_NAME = '测试程序'

// 跨窗口通讯信道TAG
export const TAG_WIN_PROVIDER = 'TAG_WIN_PROVIDER'
export const BROAD_CAST_LIST = ['broadcast_A', 'broadcast_B', 'broadcast_C']

// 渲染进程主入口
const DEV_PATH = 'http://127.0.0.1:8000'
const PROD_PATH = path.resolve(__dirname, '..', '..', 'output', 'pages', 'index.html')

let machineId = ''
export const getMachineId = () => {
    if (machineId) {
        return machineId
    }
    try {
        machineId = machineIdSync()
    } catch (err) {
        console.error('Machine ID retrieval failed:', err)
    }
    return machineId
}

// 浏览器唤起APP的自定义协议
export const PROTOCOL_URL = 'oak-fire'
// 注入渲染进程窗口的地址
export const PLAYGROUND_FILE_URL =
    process.env.NODE_ENV === 'development'
        ? DEV_PATH
        : url.format({
              protocol: 'file:',
              pathname: PROD_PATH,
              slashes: true,
          })

export const PRELOAD_FILE = path.resolve(__dirname, 'preload.js')
